package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.HeroskillMapper;
import com.xgame.server.db.model.Heroskill;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class HeroskillCsTool {
    @Resource
    private HeroskillMapper heroskillMapper;

    //插入经验副本
    public Integer insertHeroSkill(String account, String playerId, Game.HeroOneCS data) throws Exception {

        //2.插入
        List<Game.SkillDataCS> items = data.getSkillLstList();
        int length = items.size();
        Integer count = new Integer(0);
        for (int i = 0; i < length; i++) {
            Game.SkillDataCS one = items.get(i);
            Heroskill map = new Heroskill();
            map.setAccount(account);
            map.setPlayerId(playerId);
            map.setHeroId(data.getId());
            map.setSkillId(one.getId());
            map.setSkillLevel(one.getLevel());
            map.setSkillLock(one.getIslock() ? 1 : 0);
            map.setSkillUsed(one.getUsed() ? 1 : 0);

            count += heroskillMapper.insert(map);
        }

        return count;
    }

    //删除记录
    public Integer deleteHeroSkill(String account) throws Exception {
        EntityWrapper<Heroskill> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return heroskillMapper.delete(userWrapper);
    }

    //查询记录
    public List<Heroskill> selectHeroSkill(String account) throws Exception {
        EntityWrapper<Heroskill> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return heroskillMapper.selectList(userWrapper);
    }

    public List<Heroskill> selectHeroSkill(String account, Integer heroId) throws Exception {
        EntityWrapper<Heroskill> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);
        userWrapper.eq("hero_id", heroId);

        return heroskillMapper.selectList(userWrapper);
    }
}
